<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>点击按钮切换图片并改变按钮颜色</title>
    <script src="vue.js"></script>
    <link rel="stylesheet" href="./css/SpicBtn.css">
</head>
<body>
    <div id="app">
        <img :src="img1" v-if="imgSrc" width="200">
        <img :src="img2" v-if="!imgSrc" width="220"><br>
    <button @click="click1()" :class.v-if="imgSrc==true?'red':''">图片1</button>

    <button @click="click2()" :class.v-if="imgSrc==false?'red':''">图片2</button>
</div>

<script>
    var vm = new Vue({
        el:"#app",
        data(){
            return{
                img1:"img/1.jpg",
                img2:"img/2.jpg",
                imgSrc:true,
            }
        },
        methods:{
            click1(){
                this.imgSrc=true
            },
            click2(){
                this.imgSrc=false
            }
        }
    })
</script>
</body>
</html>